//
//  NewsShareView.m
//  Fireball
//
//  Created by 俞渊华 on 2017/12/11.
//  Copyright © 2017年 俞渊华. All rights reserved.
//

#import "NewsShareView.h"
#import <UMSocialCore/UMSocialCore.h>

@interface NewsShareView ()

@property(nonatomic, strong)UIView *leftLine;
@property(nonatomic, strong)UIView *rightLine;
@property(nonatomic, strong)UILabel *titleLabel;

@property(nonatomic, strong)NSArray *shareArray;
@property(nonatomic, strong)NSMutableArray *itmeArray;

@end

@implementation NewsShareView

-(instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        self.itmeArray = [NSMutableArray array];
        
        self.leftLine = [[UIView alloc] init];
        self.leftLine.backgroundColor = [UIColor xm_splitlineColor];
        [self addSubview:self.leftLine];
        
        self.rightLine = [[UIView alloc] init];
        self.rightLine.backgroundColor = [UIColor xm_splitlineColor];
        [self addSubview:self.rightLine];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.textColor = [UIColor xm_middleColor];
        self.titleLabel.font = [UIFont xm_font:15.0];
        [self addSubview:self.titleLabel];
        
        self.titleLabel.text = @"分享到";
        
        self.shareArray = @[@{@"image":@"wechat_WechatSession",@"title":@"微信好友"},
                            @{@"image":@"share_Sina",@"title":@"新浪"},
                            @{@"image":@"share_WechatTimeline",@"title":@"微信朋友圈"}];
        for (int i = 0; i < self.shareArray.count; i ++) {
            NSDictionary * dict = self.shareArray[i];
            UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button setImage:[UIImage imageNamed:dict[@"image"]] forState:UIControlStateNormal];
            button.tag = i;
            [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:button];
            [self.itmeArray addObject:button];
        }
        
        
    }
    return self;
}
-(void)buttonClick:(UIButton *)sender{
    UMSocialPlatformType type = UMSocialPlatformType_UnKnown;
    switch (sender.tag) {
        case 0:
            type = UMSocialPlatformType_WechatSession;
            break;
        case 1:
            type = UMSocialPlatformType_QQ;
            break;
        case 2:
            type = UMSocialPlatformType_WechatTimeLine;
            break;
        default:
            break;
    }

    [[XMTool shared] shareToPlatform:type viewController:self.viewController];
}


-(void)layoutSubviews{
    [super layoutSubviews];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self).offset(5);
    }];
    [self.leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.titleLabel);
        make.right.mas_equalTo(self.titleLabel.mas_left).offset(-30);
        make.height.mas_equalTo(@0.6);
        make.width.mas_equalTo(self).multipliedBy(0.3);
    }];
    [self.rightLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.titleLabel);
        make.left.mas_equalTo(self.titleLabel.mas_right).offset(30);
        make.height.mas_equalTo(@0.6);
        make.width.mas_equalTo(self).multipliedBy(0.3);
    }];
    
    CGFloat buttonW = self.width /self.itmeArray.count;
    for (int i = 0; i < self.itmeArray.count; i ++) {
        UIButton * button = self.itmeArray[i];
        button.size = CGSizeMake(buttonW, 50);
        button.x = buttonW * i;
        button.y = 60;
    }
    
}
-(void)drawRect:(CGRect)rect{
    [super drawRect:rect];
}


@end
